package com.lin.sppringbootdemo.handle;

import com.lin.sppringbootdemo.domain.ResultData;
import com.lin.sppringbootdemo.exception.TestLinException;
import com.lin.sppringbootdemo.util.ResultUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@ControllerAdvice
@Slf4j
public class ExceptionHanle {

    @ExceptionHandler(value = Exception.class)
    @ResponseBody
    public ResultData handle(Exception e) {
        if (e instanceof TestLinException) {
            TestLinException t = (TestLinException) e;
            return ResultUtil.fail(t.getCode(), t.getMessage());
        }
        log.error("[系统异常]{}", e);
        return ResultUtil.fail(e.getMessage());

    }


}